//
//  zhuceeViewController.m
//  模拟-百思不得姐
//
//  Created by 谭浔明 on 16/8/8.
//  Copyright © 2016年 chunyu. All rights reserved.
//

#import "zhuceeViewController.h"
#import "EMClient.h"
#import "LoginViewController.h"

@interface zhuceeViewController ()<UITextFieldDelegate>

//图片旋转
@property (weak, nonatomic) IBOutlet UIImageView *imageView;


@property (weak, nonatomic) IBOutlet UITextField *TF1;



@property (weak, nonatomic) IBOutlet UITextField *TF2;

@property (readwrite, nonatomic) CGFloat angle;


@end

@implementation zhuceeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self.view sendSubviewToBack:[self.view viewWithTag:20]];
    [self startAnimation];
    
    
}
//图片旋转
-(void) startAnimation
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.01];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(endAnimation)];
    _imageView.transform = CGAffineTransformMakeRotation(_angle * (M_PI / 180.0f));
    [UIView commitAnimations];
}

-(void)endAnimation
{
    _angle += 10;
    [self startAnimation];
}





- (IBAction)fanhuiBtn:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


- (IBAction)ZCBtn:(UIButton *)sender {
    
    EMError *error = [[EMClient sharedClient] registerWithUsername:_TF1.text password:_TF2.text];
    if (error==nil) {
        NSLog(@"注册成功");
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"注册成功" message:@"恭喜恭喜" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
            NSArray *array=[[NSArray alloc]initWithObjects:_TF1.text,_TF2.text,nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"loggg" object:array];
            
            [self dismissViewControllerAnimated:YES completion:nil];
            
            
            

        }];
        [alertVC addAction:action];
        [self presentViewController:alertVC animated:YES completion:^{}];

    }else{
    
        
        UIAlertController *al=[UIAlertController alertControllerWithTitle:@"注册失败" message:@"已有该账号或账号密码错误" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *ac=[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [al addAction:ac];
        [self presentViewController:al animated:YES completion:^{}];
 
    }
 
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField.tag == 10) {
        [[self.view viewWithTag:11] becomeFirstResponder];
    } else {
        [self ZCBtn:nil];
    }
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
